package cn.anlab.anappframe.net.sub;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

public abstract class ConnectionImp implements IConnection, INIOHandler, Runnable {

	private String id;
	protected InetSocketAddress remoteAddress;
	protected ByteBuffer receiveBuf;
	protected ByteBuffer sendBuf;
	protected Queue<InPacket> inQueue;
	protected Queue<OutPacket> outQueue;

	public ConnectionImp(String id) {
		this.id = id;
		this.receiveBuf = ByteBuffer.allocate(1024);
		this.sendBuf = ByteBuffer.allocate(1024);
		inQueue = new LinkedList<InPacket>();
	}

	@Override
	public void add(OutPacket out) {
		outQueue.add(out);
	}

	@Override
	public void clearSendQueue() {
		inQueue.clear();
	}

	@Override
	public String getId() {
		return id;
	}

	@Override
	public InetSocketAddress getRemoteAddress() {
		return remoteAddress;
	}

	@Override
	public INIOHandler getNIOHandler() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return false;
	}

	public void processError(Exception e) {
		// TODO ====
	}

	public OutPacket remove() {
		// TODO ====
		return null;
	}

	@Override
	public void run() {
		start(); 				
	}
	
	public void checkNewConnection() {
		//TODO ===
	}
	
	public void notifySend() {
		//TODO ===
	}
	
	public void dispatchErrorToAll(Exception e) {
		//TODO ===
	}
	

	
	
}
